package com.cinco.server.exception;

import com.cinco.server.pojo.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLException;
import java.sql.SQLIntegrityConstraintViolationException;

/**
 * @author cinco
 * @version 1.0
 * @date 2022/1/14
 */
@RestControllerAdvice
public class GlobalException {
    @ExceptionHandler(SQLException.class)
    public Result mySqlException(SQLException e){
        if (e instanceof SQLIntegrityConstraintViolationException){
            return Result.error("该数据有关联数据，操作失败");
        }
        return Result.error("数据库异常，操作失败");
    }
}
